;*****************************************************************************************************
;+
; NAME:
;       IGL_AXIS
;
; PURPOSE:
;
;       This is a basic vizualisation object which represents a single
;       axis for a plot. It is subclassed from IGL_BaseRangeObject to have all
;       the necessary pan/zoom behaviour for interactivity.
;
;
; AUTHORS:
;
;        RAPHAEL SADOUN
;        Graduate Student
;        Institut d'Astrophysique de Paris
;        98 bis boulevard Arago
;        75014 PARIS FRANCE
;        E-mail: raphael.sadoun@gmail.com
;
; SUPERCLASSES:
;
;       IGL_BASERANGEOBJECT
;
; SYNTAX:
;
;       axis = Obj_New('IGL_Axis')
;
;
; CLASS_STRUCTURE:
;
;         class = {IGL_Axis, $
;           INHERITS IGL_BASERANGEOBJECT, $ ; This is an IGL_BASERANGEOBJECT subclass
;           direction:0B, $                 ; The axis type (0=x, 1=y)
;           tickdir:0B, $                   ; The direction of the tick marks
;           xloc:0.0, $                     ; The x location of the axis in the graphic
;           yloc:0.0, $                     ; The y location of the axis in the graphic           
;           charsize:0.0, $                 ; The character size
;           charthick:0.0, $                ; The character thickness
;           color:'', $                     ; The color name of the axis
;           font:0B, $                      ; The character font
;           gridstyle:0B, $                 ; The line style for the grid
;           thick:0.0, $                    ; The axis thickness
;           minor:0L, $                     ; The number of minor tick intervals
;           tickformat:ptr_new(), $         ; The tick label format
;           tickname:ptr_new(), $           ; The tick label names
;           tickinterval:0.0, $             ; The interval between major ticks
;           ticklayout:0B, $                ; The axis layout
;           ticklen:0.0, $                  ; The length of the tick lines
;           ticks:0L, $                     ; The number of major tick intervals
;           tickunits:ptr_new(), $          ; The unit of the tick labels
;           tickv:ptr_new(), $              ; The tick label values
;           visible:0B $                    ; Flag indicating if the axis is visible
;          }
;
;
; MODIFICATION_HISTORY:
;
;       Written by: Raphael Sadoun, 24 April 2012
;-
;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::CONTROLPANEL
;
; PURPOSE:
;
;       This method creates a control panel for the graphic.
;
; SYNTAX:
;
;       self -> ControlPanel, baseObject
;
; ARGUMENTS:
;
;       baseObject:    The object reference of a base widget for this control to
;                      be added to. If not supplied, the control panel will be in a
;                      self contained window.
;
; KEYWORDS:
;
;       _EXTRA:       Any keywords appropriate for the CATCONTROLPANEL::INIT method.
;-
;*****************************************************************************************************
PRO IGL_Axis::ControlPanel, baseObject, _EXTRA=extraKeywords

   @cat_pro_error_handler

   ;; Create a new control panel
   cp = OBJ_NEW ('CatControlPanel', self, PARENT=baseObject, COLUMN=1, $
      TITLE='IGL_Plot Control Panel', _EXTRA=extraKeywords, /No_Cancel, /No_Apply, /No_OK)

   IF (NOT OBJ_VALID (cp)) THEN RETURN


   aproperties = Obj_New('PROPERTYSHEETWIDGET', cp, Value=self, Name='IGL_AXIS PROPERTYSHEET', YSize=16)
   aproperties -> SetProperty, Event_Object=self

   ;; Display the control panel if it created its own TLB.
   IF cp -> Created_Own_TLB(tlb) THEN tlb -> Draw, /Center

   self -> Report, /Completed

END

;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::DRAW
;
; PURPOSE:
;
;       This method draws the contour plot in the current display window.
;
; SYNTAX:
;
;       self -> Draw
;
; ARGUMENTS:
;
;       None.
;
; KEYWORDS:
;
;       _EXTRA:     Any keyword accepted by the CATATOM::Draw method.
;
;-
;*****************************************************************************************************
PRO IGL_Axis::Draw, _Extra=extrakeywords

   @cat_pro_error_handler

   ;; If the selectable object is invisible, then return immediately.
   IF self.visible EQ 0 THEN RETURN

   ;; Save the IDL plot variables
   cx = !x
   cy = !y
   cz = !z

   ;; Switch to decomposed color
   SetDecomposedState, 1, CURRENTSTATE=currentState

   ;; Apply the coordinate system.
   self -> ApplyCoords

   ;; Calculate the scale factor for the line thickness
   IF !D.Name EQ 'PS' THEN factor = 2.5 ELSE factor = 1.0

   ;; Switch to hardware fonts if we are in PostScript and the
   ;; requested font is Herschey
   IF (!D.Name EQ 'PS') AND (self.font EQ 0) THEN font = 1 ELSE font = self.font
   
   ;; Draw the object here.
   self._coords -> GetProperty, xrange=xrange, yrange=yrange, position=pos, xlog=xlog, ylog=ylog
   IF (pos[0] GE pos[2]) THEN return
   IF (pos[1] GE pos[3]) THEN return

   ;; Calculate the position of the axis in normalized coordinate
   x = (pos[2]-pos[0])*self.xloc+pos[0]
   y = (pos[3]-pos[1])*self.yloc+pos[1]
   
   CASE self.direction OF

      0:BEGIN                   ; x axis
         AXIS, x, y, $
               charsize=self.charsize*1.2, $
               charthick=self.charthick*factor, $
               font=font-1, $
               color=cgcolor(self.color), $
               xaxis=self.tickdir, $
               xrange=xrange, $
               xstyle=1, $
               xlog=xlog, $
               xgridstyle=self.gridstyle, $
               xthick=self.thick*factor, $
               xminor=self.minor, $
               xtickinterval=self.tickinterval, $
               xticklayout=self.ticklayout, $
               xticklen=self.ticklen, $
               xticks=self.ticks, $
               xtickformat=*self.tickformat, $
               xtickname=*self.tickname, $
               xtickunits=*self.tickunits, $
               xtickv=*self.tickv, $
               /normal
      END
      
      1:BEGIN                   ; y axis
         AXIS,  x, y, $
                charsize=self.charsize*1.2, $
                charthick=self.charthick*factor, $
                font=font-1, $
                color=cgcolor(self.color), $
                yaxis=self.tickdir, $
                yrange=yrange, $
                ystyle=1, $
                ylog=ylog, $
                ygridstyle=self.gridstyle, $
                ythick=self.thick*factor, $
                yminor=self.minor, $
                ytickinterval=self.tickinterval, $
                yticklayout=self.ticklayout, $
                yticklen=self.ticklen, $
                yticks=self.ticks, $
                ytickformat=*self.tickformat, $
                ytickname=*self.tickname, $
                ytickunits=*self.tickunits, $
                ytickv=*self.tickv, $
               /normal
      END
   ENDCASE

   ;; Restore decomposed state
   SetDecomposedState, currentState

   ;; Save the coordinate system
   !igl_x = !x
   !igl_y = !y
   !igl_z = !z

   ;; Restore the IDL plot variables
   !x = cx
   !y = cy
   !z = cz

   ;; Draw the children
   self -> CatAtom::Draw, _EXTRA=extra

   ;; Report completion
   self -> Report, /Completed

END


;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::EVENTHANDLER
;
; PURPOSE:
;
;       This method is an event handler for the Control Panel.
;
; SYNTAX:
;
;       Called automatically by the event handling system
;
; ARGUMENTS:
;
;       event:  The event structure.
;
; KEYWORDS:
;
;       None.
;-
;*****************************************************************************************************
PRO IGL_Axis::EventHandler, event

   @cat_pro_error_handler

   ; Get the name of the widget generating the event. Branch on this.
   event.ID -> GetProperty, Name=eventName
   CASE eventName OF

      'IGL_AXIS PROPERTYSHEET': BEGIN

         IF event.type EQ 0 THEN BEGIN
            
            CASE StrUpCase(event.identifier) OF

               'COLOR': BEGIN

                  event.component -> GetProperty, Color=color
                  event.id -> GetProperty, ID=group_leader
                  color = PickColorName(color, Group_Leader=group_leader)
                  event.component -> SetProperty, Color=color
                  
                  ;; Refresh graphic hierarchy
                  IGL_RefreshDraw, event.component, /Buffered_Output

               END

               ELSE: BEGIN

                  component = event.component
                  identifier = event.identifier
                  event.id -> GetProperty, Value=value, Component=component, Property_Value=identifier
                  event.component -> SetPropertyByIdentifier, identifier, value

                  ;; Refresh graphic hierarchy
                  IF OBJ_VALID(event.component) THEN IGL_RefreshDraw, event.component, /Buffered_Output

               END

            ENDCASE

         ENDIF ; of BUTTON DOWN EVENT

         END 

        ; If you can't handle the event here. Pass it along to superclass EventHandler
        ELSE: self -> IGL_BaseRangeObject::EventHandler, event

   ENDCASE

   ;; Report completion
   IF Obj_Valid(self) THEN self -> Report, /Completed

END

;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::GETPROPERTY
;
; PURPOSE:
;
;       This method is used to get the object's properties.
;
; SYNTAX:
;
;       self -> GetProperty
;
; ARGUMENTS:
;
;     None.
;
; KEYWORDS:
;
;    TICKDIR:      The direction of the tick marks. For an X axis,
;                  0=pointing up, 1=pointing down. For an Y axis,
;                  0=pointing right, 1=pointing left. The default is 0.
;
;    XLOC:         The x location of the axis in the plot window
;                  (corresponding to the position of the coordinate
;                  system associated with the axis). For example,
;                  an Y axis positionned at xloc=0.0 is at the left
;                  of the plot. The default is 0.0.
;
;    YLOC:         The y location of the axis in the plot window
;                  (corresponding to the position of the coordinate
;                  system associated with the axis). For example,
;                  an X axis positionned at yloc=0.0 is at the bottom
;                  of the plot. The default is 0.0.
;
;    COLOR:        The color of the axis.
;
;    CHARSIZE:     The character size.
;                         
;    CHARTHICK:    The character thickness.
;              
;    FONT:         The character font.
;              
;    GRIDSTYLE:    The line style for the grid.
;              
;    THICK:        The axis thickness.
;              
;    MINOR:        The number of minor tick intervals.
;              
;    TICKFORMAT:   The tick label format.
;              
;    TICKNAME:     The tick label names.
;              
;    TICKINTERVAL: The interval between major ticks.
;              
;    TICKLAYOUT:   The axis layout.
;              
;    TICKLEN:      The length of the tick lines.
;              
;    TICKS:        The number of major tick intervals.
;              
;    TICKUNITS:    The unit of the tick labels.
;              
;    TICKV:        The tick label values.
;
;    VISIBLE:      The flag indicating if the axis is visible.
;
;    _REF_EXTRA:   Any keywords appropriate for the superclass GetProperty method.
;-
;*****************************************************************************************************
PRO IGL_Axis::GetProperty, COLOR=color, $
                           CHARSIZE=charsize, $
                           CHARTHICK=charthick, $
                           FONT=font, $
                           GRIDSTYLE=gridstyle, $
                           MINOR=minor, $
                           TICKDIR=tickdir, $
                           TICKFORMAT=tickformat, $
                           TICKNAME=tickname, $
                           TICKINTERVAL=tickinterval, $
                           TICKLAYOUT=ticklayout, $
                           TICKLEN=ticklen, $
                           TICKS=ticks, $
                           TICKUNITS=tickunits, $
                           TICKV=tickv, $
                           XLOC=xloc, $
                           YLOC=yloc, $
                           THICK=thick, $
                           VISIBLE=visible, $                           
                           _REF_EXTRA=extraKeywords

   @cat_pro_error_handler

   IF (arg_present(color)) THEN color = self.color
   IF (arg_present(charsize)) THEN charsize = self.charsize
   IF (arg_present(charthick)) THEN charthick = self.charthick
   IF (arg_present(font)) THEN font = self.font
   IF ARG_PRESENT(gridstyle) THEN gridstyle = self.gridstyle
   IF ARG_PRESENT(minor) THEN minor = self.minor
   IF (arg_present(tickformat)) THEN tickformat = *self.tickformat
   IF ARG_PRESENT(tickname) THEN tickname = *self.tickname
   IF ARG_PRESENT(tickunits) THEN tickunits = *self.tickunits
   IF ARG_PRESENT(tickv) THEN tickv = *self.tickv
   IF ARG_PRESENT(ticklen) THEN ticklen = self.ticklen
   IF ARG_PRESENT(tickdir) THEN tickdir = self.tickdir
   IF ARG_PRESENT(ticks) THEN ticks = self.ticks
   IF ARG_PRESENT(ticklayout) THEN ticklayout = self.ticklayout
   IF ARG_PRESENT(tickinterval) THEN tickinterval = self.tickinterval
   IF (arg_present(visible)) THEN visible = self.visible
   IF (arg_present(xloc)) THEN xloc = self.xloc
   IF (arg_present(yloc)) THEN yloc = self.yloc
   IF ARG_PRESENT(thick) THEN thick = self.thick
   
   IF (N_ELEMENTS (extraKeywords) GT 0) THEN self -> IGL_BASERANGEOBJECT::GetProperty, _EXTRA=extraKeywords

   self -> Report, /Completed

END

;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::SETPROPERTY
;
; PURPOSE:
;
;       This method is used to set the object's properties.
;
; SYNTAX:
;
;       self -> SetProperty
;
; ARGUMENTS:
;
;     None.
;
; KEYWORDS:
;              
;    TICKDIR:      The direction of the tick marks. For an X axis,
;                  0=pointing up, 1=pointing down. For an Y axis,
;                  0=pointing right, 1=pointing left. The default is 0.
;
;    XLOC:         The x location of the axis in the plot window
;                  (corresponding to the position of the coordinate
;                  system associated with the axis). For example,
;                  an Y axis positionned at xloc=0.0 is at the left
;                  of the plot. The default is 0.0.
;
;    YLOC:         The y location of the axis in the plot window
;                  (corresponding to the position of the coordinate
;                  system associated with the axis). For example,
;                  an X axis positionned at yloc=0.0 is at the bottom
;                  of the plot. The default is 0.0.
;
;    COLOR:        The color of the axis.
;
;    CHARSIZE:     The character size.
;                         
;    CHARTHICK:    The character thickness.
;              
;    FONT:         The character font.
;              
;    GRIDSTYLE:    The line style for the grid.
;              
;    THICK:        The axis thickness.
;              
;    MINOR:        The number of minor tick intervals.
;              
;    TICKFORMAT:   The tick label format.
;              
;    TICKNAME:     The tick label names.
;              
;    TICKINTERVAL: The interval between major ticks.
;              
;    TICKLAYOUT:   The axis layout.
;              
;    TICKLEN:      The length of the tick lines.
;              
;    TICKS:        The number of major tick intervals.
;              
;    TICKUNITS:    The unit of the tick labels.
;              
;    TICKV:        The tick label values.
;
;    VISIBLE:      The flag indicating if the axis is visible.
;
;    _EXTRA:       Any keyword accepted by the SetProperty method of
;                  the IGL_BASERANGEOBJECT superclass.
;-
;*****************************************************************************************************
PRO IGL_Axis::SetProperty, COLOR=color, $
                           VISIBLE=visible, $
                           CHARSIZE=charsize, $
                           CHARTHICK=charthick, $
                           FONT=font, $
                           GRIDSTYLE=gridstyle, $
                           MINOR=minor, $
                           TICKDIR=tickdir, $
                           TICKFORMAT=tickformat, $
                           TICKNAME=tickname, $
                           TICKINTERVAL=tickinterval, $
                           TICKLAYOUT=ticklayout, $
                           TICKLEN=ticklen, $
                           TICKS=ticks, $
                           TICKUNITS=tickunits, $
                           TICKV=tickv, $
                           THICK=thick, $
                           XLOC=xloc, $
                           YLOC=yloc, $
                           _EXTRA=extraKeywords

   @cat_pro_error_handler

   IF (n_elements(charsize) NE 0) THEN self.charsize = charsize
   IF (n_elements(charthick) NE 0) THEN self.charthick = charthick
   IF (n_elements(font) NE 0) THEN self.font = font
   IF N_ELEMENTS(minor) NE 0 THEN self.minor = minor
   IF N_ELEMENTS(gridstyle) NE 0 THEN self.gridstyle = gridstyle
   IF (n_elements(tickformat) NE 0) THEN BEGIN
      PTR_FREE, self.tickformat
      self.tickformat = PTR_NEW(tickformat)
   ENDIF
   IF N_ELEMENTS(tickname) NE 0 THEN BEGIN
      PTR_FREE, self.tickname
      self.tickname = PTR_NEW(tickname)
   ENDIF
   IF N_ELEMENTS(tickunits) NE 0 THEN BEGIN
      PTR_FREE, self.tickunits
      self.tickunits = PTR_NEW(tickunits)
   ENDIF
   IF N_ELEMENTS(tickv) NE 0 THEN BEGIN
      PTR_FREE, self.tickv
      self.tickv = PTR_NEW(tickv)
   ENDIF

   
   IF N_ELEMENTS(tickdir) NE 0 THEN self.tickdir = tickdir
   IF N_ELEMENTS(ticks) NE 0 THEN self.ticks = ticks
   IF N_ELEMENTS(ticklen) NE 0 THEN self.ticklen = ticklen
   IF N_ELEMENTS(ticklayout) NE 0 THEN self.ticklayout = ticklayout
   IF N_ELEMENTS(tickinterval) NE 0 THEN self.tickinterval = tickinterval
   
   IF (n_elements(visible) NE 0) THEN self.visible = visible
   
   IF (n_elements(color) NE 0) THEN BEGIN
      self.color = color
      self -> SetPropertyAttribute, 'COLOR', USERDEF=CapFirstLetter(self.color)
      IF Obj_Valid(self._controlpanel) THEN self._controlpanel -> Refresh_Properties, Properties='COLOR'
   ENDIF

   IF (n_elements(xloc) NE 0) THEN self.xloc = xloc
   IF (n_elements(yloc) NE 0) THEN self.yloc = yloc
   IF N_ELEMENTS(thick) NE 0 THEN self.thick = thick

   self -> IGL_BASERANGEOBJECT::SetProperty, _EXTRA=extraKeywords

   IF OBJ_VALID(self) THEN self -> Report, /Completed

END

;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::CLEANUP
;
; PURPOSE:
;
;       This is the IGL_Axis object class destructor method.
;
; SYNTAX:
;
;       Called automatically when the object is destroyed.
;
;
; ARGUMENTS:
;
;     None.
;
; KEYWORDS:
;
;     None.
;-
;*****************************************************************************************************
PRO IGL_Axis::CLEANUP

   @cat_pro_error_handler

   PTR_FREE, self.tickformat
   PTR_FREE, self.tickname
   PTR_FREE, self.tickunits
   PTR_FREE, self.tickv

   self -> IGL_BASERANGEOBJECT::CLEANUP

   self -> Report, /Completed

END


;*****************************************************************************************************
;+
; NAME:
;       IGL_Axis::INIT
;
; PURPOSE:
;
;       This is the IGL_Axis object class creator method.
;
; SYNTAX:
;
;       Called automatically when the object is created.
;
; ARGUMENTS:
;
;     None.
;
; KEYWORDS:
;
;    DIRECTION:    The axis type (0=X axis, 1=Y axis). The default is 0.
;              
;    TICKDIR:      The direction of the tick marks. For an X axis,
;                  0=pointing up, 1=pointing down. For an Y axis,
;                  0=pointing right, 1=pointing left. The default is 0.
;
;    XLOC:         The x location of the axis in the plot window
;                  (corresponding to the position of the coordinate
;                  system associated with the axis). For example,
;                  an Y axis positionned at xloc=0.0 is at the left
;                  of the plot. The default is 0.0.
;
;    YLOC:         The y location of the axis in the plot window
;                  (corresponding to the position of the coordinate
;                  system associated with the axis). For example,
;                  an X axis positionned at yloc=0.0 is at the bottom
;                  of the plot. The default is 0.0.
;
;    COLOR:        The color of the axis.
;
;    CHARSIZE:     The character size.
;                         
;    CHARTHICK:    The character thickness.
;              
;    FONT:         The character font.
;              
;    GRIDSTYLE:    The line style for the grid.
;              
;    THICK:        The axis thickness.
;              
;    MINOR:        The number of minor tick intervals.
;              
;    TICKFORMAT:   The tick label format.
;              
;    TICKNAME:     The tick label names.
;              
;    TICKINTERVAL: The interval between major ticks.
;              
;    TICKLAYOUT:   The axis layout.
;              
;    TICKLEN:      The length of the tick lines.
;              
;    TICKS:        The number of major tick intervals.
;              
;    TICKUNITS:    The unit of the tick labels.
;              
;    TICKV:        The tick label values.
;
;    _EXTRA:       Any keyword accepted by the IGL_BASERANGEOBJECT::Init method.
;
;-
;*****************************************************************************************************
FUNCTION IGL_Axis::INIT, DIRECTION=direction, $
                         TICKDIR=tickdir, $
                         XLOC=xloc, $
                         YLOC=yloc, $
                         COLOR=color, $
                         CHARSIZE=charsize, $
                         CHARTHICK=charthick, $
                         FONT=font, $
                         GRIDSTYLE=gridstyle, $
                         THICK=thick, $
                         MINOR=minor, $
                         TICKFORMAT=tickformat, $
                         TICKNAME=tickname, $
                         TICKINTERVAL=tickinterval, $
                         TICKLAYOUT=ticklayout, $
                         TICKLEN=ticklen, $
                         TICKS=ticks, $
                         TICKUNITS=tickunits, $
                         TICKV=tickv, $
                         _EXTRA=extraKeywords

   ; Set up error handler
   @cat_func_error_handler

   ;; Initialize the global system variables
   IGL_InitSysVars

   ;; Default keyword values
   IF (n_elements(direction) EQ 0) THEN direction = 0
   IF (n_elements(tickdir) EQ 0) THEN tickdir = 0
   IF (n_elements(xloc) EQ 0) THEN  xloc = 0
   IF (n_elements(yloc) EQ 0) THEN yloc = 0
   IF (n_elements(color) EQ 0) THEN color = !IGL_P.axiscolor
   IF (n_elements(charsize) EQ 0) THEN charsize = (!IGL_P.charsize EQ 0) ? 1 : !IGL_P.charsize
   IF (n_elements(charthick) EQ 0) THEN charthick = (!IGL_P.charthick EQ 0) ? 1 : !IGL_P.charthick
   IF (n_elements(font) EQ 0) THEN font = !IGL_P.font+1
   IF (n_elements(ticklen) EQ 0) THEN ticklen = !IGL_P.ticklen

   CASE direction OF

      0: BEGIN

         IF N_ELEMENTS(gridstyle) EQ 0 THEN gridstyle = !IGL_X.gridstyle
         IF N_ELEMENTS(thick) EQ 0 THEN thick = (!IGL_X.thick EQ 0) ? 1 : !IGL_X.thick
         IF N_ELEMENTS(minor) EQ 0 THEN minor = !IGL_X.minor
         IF N_ELEMENTS(tickformat) EQ 0 THEN tickformat = !IGL_X.tickformat
         IF N_ELEMENTS(tickname) EQ 0 THEN tickname = !IGL_X.tickname
         IF N_ELEMENTS(tickinterval) EQ 0THEN tickinterval = !IGL_X.tickinterval
         IF N_ELEMENTS(ticklayout) EQ 0 THEN ticklayout = !IGL_X.ticklayout
         IF N_ELEMENTS(ticks) EQ 0 THEN ticks = !IGL_X.ticks 
         IF N_ELEMENTS(tickunits) EQ 0 THEN tickunits = !IGL_X.tickunits
         IF N_ELEMENTS(tickv) EQ 0 THEN tickv = !IGL_X.tickv

      END

      1: BEGIN

         IF N_ELEMENTS(gridstyle) EQ 0 THEN gridstyle = !IGL_Y.gridstyle
         IF N_ELEMENTS(thick) EQ 0 THEN thick = !IGL_Y.thick
         IF N_ELEMENTS(minor) EQ 0 THEN minor = !IGL_Y.minor
         IF N_ELEMENTS(tickformat) EQ 0THEN tickformat = !IGL_Y.tickformat
         IF N_ELEMENTS(tickname) EQ 0 THEN tickname = !IGL_Y.tickname
         IF N_ELEMENTS(tickinterval) EQ 0THEN tickinterval = !IGL_Y.tickinterval
         IF N_ELEMENTS(ticklayout) EQ 0 THEN ticklayout = !IGL_Y.ticklayout
         IF N_ELEMENTS(ticks) EQ 0 THEN ticks = !IGL_Y.ticks
         IF N_ELEMENTS(tickunits) EQ 0 THEN tickunits = !IGL_Y.tickunits
         IF N_ELEMENTS(tickv) EQ 0 THEN tickv = !IGL_Y.tickv

      END

      ELSE: message, 'Invalid value for DIRECTION keyword'

   ENDCASE
 
   ;; Get a name fot the axis
   axisNames = ['X axis', 'Y axis']
   name = axisNames[direction]

   ok = self -> IGL_BASERANGEOBJECT::INIT(NAME=name, $
                                          DESCRIPTION='Single axis', $
                                          _EXTRA=extraKeywords)
   IF (NOT ok) THEN RETURN, 0

   ; Load object.
   self.direction = direction
   self.tickdir = keyword_set(tickdir)
   self.xloc = xloc
   self.yloc = yloc
   self.color = color
   self.charsize = charsize > 0.1
   self.charthick = charthick > 1
   self.font = 0 > font < 2
   self.thick = thick > 1
   self.gridstyle = gridstyle
   self.minor = minor > 0
   self.tickinterval = tickinterval
   self.ticklayout= ticklayout
   self.ticklen = 0 > ticklen < 1
   self.ticks = ticks > 0
   self.tickformat = PTR_NEW(tickformat,/ALLOCATE_HEAP)
   self.tickname = PTR_NEW(tickname,/ALLOCATE_HEAP)
   self.tickunits = PTR_NEW(tickunits,/ALLOCATE_HEAP)
   self.tickv = PTR_NEW(tickv,/ALLOCATE_HEAP)
   self.visible = 1

   ; Register properties for the property sheet.
   self -> SetPropertyAttribute, 'name', sensitive=0
   self -> SetPropertyAttribute, 'description', sensitive=0
   self -> RegisterProperty, 'XLOC', /float, name='Axis Location'
   self -> RegisterProperty, 'YLOC', /float, name='Axis Location'
   self -> RegisterProperty, 'FONT', name='Character Font', enumlist=['Herschey','Hardware','True Type']
   self -> RegisterProperty, 'CHARSIZE', /float, name='Character Size', valid_range=[0.1,10.0]
   self -> RegisterProperty, 'CHARTHICK', /integer, name='Character Thickness', valid_range=[1,10]
   self -> RegisterProperty, 'COLOR', 0, name='Color', USERDEF=CapFirstLetter(self.color)
   self -> RegisterProperty, 'GRIDSTYLE', /linestyle, name='Grid Linestyle'
   self -> RegisterProperty, 'THICK', /integer, name='Line Thickness', valid_range=[1,10]
   self -> RegisterProperty, 'TICKDIR', 9, name='Tick Direction', enumlist=['Top','Bottom']
   self -> RegisterProperty, 'TICKLAYOUT', name='Tick Layout', enumlist=['Normal','Only Labels','Box Style']
   self -> RegisterProperty, 'TICKLEN', /float, name='Tick Length', valid_range=[-1.0,1.0]  
   IF (direction EQ 0) THEN BEGIN
      self -> SetPropertyAttribute, 'TICKDIR', enumlist=['Top','Bottom']
      self -> SetPropertyAttribute, 'YMIN', /HIDE
      self -> SetPropertyAttribute, 'YMAX', /HIDE
      self -> SetPropertyAttribute, 'YLOG', /HIDE
      self -> SetPropertyAttribute, 'XLOC', /HIDE
   ENDIF
   IF (direction EQ 1) THEN BEGIN
      self -> SetPropertyAttribute, 'TICKDIR', enumlist=['Right','Left']
      self -> SetPropertyAttribute, 'XMIN', /HIDE
      self -> SetPropertyAttribute, 'XMAX', /HIDE
      self -> SetPropertyAttribute, 'XLOG', /HIDE
      self -> SetPropertyAttribute, 'YLOC', /HIDE
   ENDIF

   ;; Report completion
   self -> Report, /Completed

   RETURN, 1

END


;*****************************************************************************************************
;
; NAME:
;       IGL_AXIS CLASS DEFINITION
;
; PURPOSE:
;
;       This is the IGL_Axis object's structure definition code.
;
;*****************************************************************************************************
PRO IGL_Axis__Define, class

  COMPILE_OPT idl2, HIDDEN

  class = {IGL_Axis, $
           INHERITS IGL_BASERANGEOBJECT, $ ; This is an IGL_BASERANGEOBJECT subclass
           direction:0B, $                 ; The axis type (0=x, 1=y)
           tickdir:0B, $                   ; The direction of the tick marks
           xloc:0.0, $                     ; The x location of the axis in the graphic
           yloc:0.0, $                     ; The y location of the axis in the graphic           
           charsize:0.0, $                 ; The character size
           charthick:0.0, $                ; The character thickness
           color:'', $                     ; The color name of the axis
           font:0B, $                      ; The character font
           gridstyle:0B, $                 ; The line style for the grid
           thick:0.0, $                    ; The axis thickness
           minor:0L, $                     ; The number of minor tick intervals
           tickformat:ptr_new(), $         ; The tick label format
           tickname:ptr_new(), $           ; The tick label names
           tickinterval:0.0, $             ; The interval between major ticks
           ticklayout:0B, $                ; The axis layout
           ticklen:0.0, $                  ; The length of the tick lines
           ticks:0L, $                     ; The number of major tick intervals
           tickunits:ptr_new(), $          ; The unit of the tick labels
           tickv:ptr_new(), $              ; The tick label values
           visible:0B $                    ; Flag indicating if the axis is visible
          }

  struct_hide, class

END

